from langchain_core.messages import HumanMessage, AIMessage, ToolMessage, FunctionMessage
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder, SystemMessagePromptTemplate, \
    HumanMessagePromptTemplate
from langchain_core.output_parsers import StrOutputParser, JsonOutputParser
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langchain_core.runnables import RunnablePassthrough

OPENAPI_API_BASE_3 = "https://api.xty.app/v1"
OPENAPI_API_KEY_3 = "sk-cy1Pz61qsy5q97VM9e8eA1D173604b17Bd7a11Ed4cB8C136"

chat = ChatOpenAI(
    model="gpt-3.5-turbo-0125",
    base_url=OPENAPI_API_BASE_3,
    api_key=OPENAPI_API_KEY_3,
)
prompt = ChatPromptTemplate.from_messages([
    SystemMessagePromptTemplate.from_template("你是一个聪明的ai助手,返回结果为json格式"),
    HumanMessagePromptTemplate.from_template("帮我极致精简回答问题：{question}"),
])

chain = prompt | chat | JsonOutputParser()
result = chain.invoke({
    "question": "1+1"
})
print(result)
